﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DAO
{
    public class DiaDiemDealDAO
    {
        
        private FDeal4Entities db;

        public DiaDiemDealDAO()
        {
            db = new FDeal4Entities();
        }

        public List<DIADIEMDEAL> LietKe()
        {
            return db.DIADIEMDEAL.ToList();
        }

        public DIADIEMDEAL LayID(string id)
        {
            var tl = db.DIADIEMDEAL.SingleOrDefault(t => t.IDDIADIEM == id);
            return tl;
        }

        public DIADIEMDEAL TimTen(String keyWord)
        {
            var tl = db.DIADIEMDEAL.SingleOrDefault(t => t.DIACHI.Contains(keyWord));
            return tl;
        }

        public bool Them(DIADIEMDEAL tl)
        {
            try
            {
                db.DIADIEMDEAL.AddObject(tl);
                db.SaveChanges();
                return true;
            }
            catch (System.Exception ex)
            {
                return false;
            }
        }

        public bool Xoa(DIADIEMDEAL tl)
        {
            try
            {
                db.DIADIEMDEAL.DeleteObject(tl);
                db.SaveChanges();
                return true;
            }
            catch (System.Exception ex)
            {
                return false;
            }
        }

        public bool Sua(DIADIEMDEAL tl)
        {
            try
            {
                DIADIEMDEAL t1 = db.DIADIEMDEAL.Single(t => t.IDDIADIEM == tl.IDDIADIEM);
                t1.IDDIADIEM = tl.IDDIADIEM;
                t1.DIACHI = tl.DIACHI;
                t1.TINH = tl.TINH;


                db.SaveChanges();
                return true;
            }
            catch (System.Exception ex)
            {
            	return false;
            }
        }
    }
}
